import 'package:guochaoapp/model/address_entity.dart';

addressEntityFromJson(AddressEntity data, Map<String, dynamic> json) {
	if (json['success'] != null) {
		data.success = json['success'];
	}
	if (json['msg'] != null) {
		data.msg = json['msg'].toString();
	}
	if (json['code'] != null) {
		data.code = json['code'] is String
				? int.tryParse(json['code'])
				: json['code'].toInt();
	}
	if (json['data'] != null) {
		data.data = new AddressData().fromJson(json['data']);
	}
	if (json['sign'] != null) {
		data.sign = json['sign'];
	}
	return data;
}

Map<String, dynamic> addressEntityToJson(AddressEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['success'] = entity.success;
	data['msg'] = entity.msg;
	data['code'] = entity.code;
	if (entity.data != null) {
		data['data'] = entity.data.toJson();
	}
	data['sign'] = entity.sign;
	return data;
}

addressDataFromJson(AddressData data, Map<String, dynamic> json) {
	if (json['records'] != null) {
		data.records = new List<AddressDataRecord>();
		(json['records'] as List).forEach((v) {
			data.records.add(new AddressDataRecord().fromJson(v));
		});
	}
	if (json['total'] != null) {
		data.total = json['total'] is String
				? int.tryParse(json['total'])
				: json['total'].toInt();
	}
	if (json['size'] != null) {
		data.size = json['size'] is String
				? int.tryParse(json['size'])
				: json['size'].toInt();
	}
	if (json['current'] != null) {
		data.current = json['current'] is String
				? int.tryParse(json['current'])
				: json['current'].toInt();
	}
	if (json['orders'] != null) {
		data.orders = new List<dynamic>();
		data.orders.addAll(json['orders']);
	}
	if (json['searchCount'] != null) {
		data.searchCount = json['searchCount'];
	}
	if (json['pages'] != null) {
		data.pages = json['pages'] is String
				? int.tryParse(json['pages'])
				: json['pages'].toInt();
	}
	return data;
}

Map<String, dynamic> addressDataToJson(AddressData entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	if (entity.records != null) {
		data['records'] =  entity.records.map((v) => v.toJson()).toList();
	}
	data['total'] = entity.total;
	data['size'] = entity.size;
	data['current'] = entity.current;
	if (entity.orders != null) {
		data['orders'] =  [];
	}
	data['searchCount'] = entity.searchCount;
	data['pages'] = entity.pages;
	return data;
}

addressDataRecordFromJson(AddressDataRecord data, Map<String, dynamic> json) {
	if (json['addrId'] != null) {
		data.addrId = json['addrId'] is String
				? int.tryParse(json['addrId'])
				: json['addrId'].toInt();
	}
	if (json['receiverName'] != null) {
		data.receiverName = json['receiverName'].toString();
	}
	if (json['receiverPhone'] != null) {
		data.receiverPhone = json['receiverPhone'].toString();
	}
	if (json['receiverAddr'] != null) {
		data.receiverAddr = json['receiverAddr'].toString();
	}
	if (json['isDefault'] != null) {
		data.isDefault = json['isDefault'];
	}
	return data;
}

Map<String, dynamic> addressDataRecordToJson(AddressDataRecord entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['addrId'] = entity.addrId;
	data['receiverName'] = entity.receiverName;
	data['receiverPhone'] = entity.receiverPhone;
	data['receiverAddr'] = entity.receiverAddr;
	data['isDefault'] = entity.isDefault;
	return data;
}